# This is a gmake makefile
#
# To build, run "gmake"
#
#

PACKAGES=websphinx websphinx.util websphinx.workbench websphinx.searchengine symantec.itools.awt 

LIBRARIES=gd graph com.oroinc.text.regex

JAVAC=javac
#JAVAC=jikes

JFLAGS=
#JFLAGS=-deprecation


DIRS=$(subst .,/,$(PACKAGES))
SOURCES=$(wildcard $(foreach PKG,$(DIRS),$(PKG)/*.java))
PUBLIC_CLASSES=$(subst .java,.class,$(SOURCES))
PROJECT_CLASSES=$(wildcard $(foreach PKG,$(DIRS),$(PKG)/*.class))

LIBRARY_DIRS=$(subst .,/,$(LIBRARIES))
LIBRARY_CLASSES=$(wildcard $(foreach PKG,$(LIBRARY_DIRS),$(PKG)/*.class))

RELEASE_DIR=/afs/cs/user/rcm/www/websphinx

PROJECT=websphinx

CERTIFICATE=Robert C Miller's VeriSign Trust Network ID

ifndef RECURSIVE
	export RECURSIVE=1
	CHANGED_SOURCES=$(shell $(MAKE) -s $(PUBLIC_CLASSES))
endif

all:
	$(JAVAC) $(JFLAGS) $(CHANGED_SOURCES)

clean:
	rm -rf $(PROJECT_CLASSES)

rebuild:
	$(JAVAC) $(JFLAGS) $(SOURCES)

release-all: release-zip release-jar release-source release-doc release-html

release-zip:
	$(MAKE) jdk1.0
	$(MAKE) rebuild JFLAGS=-O
	rm -rf $(RELEASE_DIR)/$(PROJECT).zip
	zip -r0 $(RELEASE_DIR)/$(PROJECT).zip $(PROJECT_CLASSES) $(LIBRARY_CLASSES)

release-jar:
	$(MAKE) jdk1.1
	$(MAKE) rebuild JFLAGS=-O
	mkdir $(RELEASE_DIR)/new
	tar -cf - $(PROJECT_CLASSES) $(LIBRARY_CLASSES) | (cd $(RELEASE_DIR)/new ; tar -xf - )
	cd $(RELEASE_DIR)/new ; signtool -k"$(CERTIFICATE)" -Z ../$(PROJECT).jar .
	rm -rf $(RELEASE_DIR)/new

release-source:
	rm -f $(PROJECT)-src.zip
	zip -r9 $(PROJECT)-src.zip README LICENSE* Makefile ifdef $(SOURCES) $(PROJECT_CLASSES) $(LIBRARY_CLASSES)

release-doc:
	javadoc -d $(RELEASE_DIR)/doc $(PACKAGES)

release-html:
	cp public-html/*.html LICENSE $(RELEASE_DIR)

jdk1.0:
	ifdef +JDK1.0 -JDK1.1 $(SOURCES)
	echo "jdk1.0" > version
	$(MAKE) clean

jdk1.1:
	ifdef -JDK1.0 +JDK1.1 $(SOURCES)
	echo "jdk1.1" > version
	$(MAKE) clean


%.class: %.java
	@echo $<

